import java.util.Date;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class HelloScheduler {

	public static void main(String[] args) {
		// 创建JobDetail
		JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).withIdentity("myjob1", "group1").build();
		// 创建Trigger实例，定义这个job立即执行，并且每2秒执行一次
		Trigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger", "group1").startNow()
				.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(2).repeatForever()).build();
		// 创建Scheduler实例
		SchedulerFactory sdf = new StdSchedulerFactory();
		try {
			Scheduler scheduler = sdf.getScheduler();
			scheduler.start();
			System.out.println("Scheduler..." + new Date().toGMTString());
			scheduler.scheduleJob(jobDetail, trigger);
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}

}
